package com.hp.provider.web;

import com.hp.provider.rabbit.IMessageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 发送消息tx
 *
 * @author <a href="mailto:xing.dong@sha.ontime-express.com">Xavier Dong</a>
 * @date
 */
@Controller
public class SendMessageTx {

    @Resource
    private IMessageService messageService;

    @RequestMapping("/sendMoreMsgTx")
    @ResponseBody
    public String sendMoreMsgTx() {
        //发送10条消息
        for (int i = 0; i < 10; i++) {
            String msg = "msg" + i;
            System.out.println("发送消息  msg：" + msg);
            messageService.sendMessage("directExchangeTx", "directQueueTxRoutingKey", msg);
            //每两秒发送一次
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "send ok";
    }
}